$(document).ready(function(){
	
	localStorage.clear();
	
	$("#calculation_method").change(function(){
		var selectedValue=$(this).val();
		if(selectedValue==1){
			$('.total_price').hide()
		}
		else $('.total_price').show()
	})
	
 $("#hpf_loans").change(function(){
    		var price2_z = $('#price2_z').val();
    		var hpf_loans  = $('#hpf_loans').val();
    		$('#commercial_loan').val(price2_z-hpf_loans);
    		
  });
  
   $("#commercial_loan").change(function(){
    		var price2_z = $('#price2_z').val();
    		
    		var commercial_loan  = $('#commercial_loan').val();
    		
    		
    		$('#hpf_loans').val(price2_z-commercial_loan);
    		
  });
  
  $("#price_z").change(function(){//房价总额
    		var price_z = $('#price_z').val();
    		var proportion  = $('#proportion').val();
    		
    		$('#price2_z').val(price_z*proportion);//贷款总额
    		$("#hpf_loans").val('0');
    		$("#commercial_loan").val('0');
  });
  $('#price2_z').change(function(){//贷款总额
    		$("#hpf_loans").val('0');
    		$("#commercial_loan").val('0');
    		if($("#price_z").val()!=0 && $("#price_z").val()!=""){
    			var price_z = $('#price_z').val();
    			var proportion  = $('#proportion').val();
    			$('#price2_z').val(price_z*proportion);//贷款总额
    		}
  });
  
  
  	$('.rmb_input').blur('input',function(){
  	 	
  	 		if(!isPInt($(this).val())){
  	 			$(this).val("");
  	 		}
  	 		
  	 })
  	 function isPInt(str) {//是否是正整数
    	var g = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
    	return g.test(str);
	}
   $("#proportion").change(function(){
		var price_z = $('#price_z').val();
		var proportion  = $('#proportion').val();
		
		$('#price2_z').val(price_z*proportion);
    		
  });
  
  $("#year").change(function(){
  		if($(this).val()<2){
			$("#lending_rate_commercial").empty().append('<option value="0.0435">商业基准利率(4.35%)</option><option value="0.0413">商业基准利率9.5折</option><option value="0.0391">商业基准利率9折</option><option value="0.0383">商业基准利率8.8折</option><option value="0.0378">商业基准利率8.7折</option><option value="0.0374">商业基准利率8.6折</option><option value="0.0370">商业基准利率8.5折</option><option value="0.0357">商业基准利率8.2折</option><option value="0.0348">商业基准利率8折</option><option value="0.0326">商业基准利率7.5折</option><option value="0.0304">商业基准利率7折</option><option value="0.0497">商业基准利率1.1倍</option><option value="0.0522">商业基准利率1.2倍</option><option value="0.0565">商业基准利率1.3倍</option>')
			$("#lending_rate_hpf").empty().append('<option value="0.0275">公积金基准利率1倍（2.75%）</option><option value="0.03025">公积金基准利率1.1倍</option><option value="0.033">公积金基准利率1.2倍</option>')
  		}else if($(this).val()>=2 && $(this).val()<=5){
			$("#lending_rate_commercial").empty().append('<option value="0.0475">商业基准利率(4.75%)</option><option value="0.0451">商业基准利率9.5折</option><option value="0.0427">商业基准利率9折</option><option value="0.0418">商业基准利率8.8折</option><option value="0.0413">商业基准利率8.7折</option><option value="0.0409">商业基准利率8.6折</option><option value="0.0404">商业基准利率8.5折</option><option value="0.0389">商业基准利率8.2折</option><option value="0.0380">商业基准利率8折</option><option value="0.0356">商业基准利率7.5折</option><option value="0.0332">商业基准利率7折</option><option value="0.0523">商业基准利率1.1倍</option><option value="0.0570">商业基准利率1.2倍</option><option value="0.0617">商业基准利率1.3倍</option>')
			$("#lending_rate_hpf").empty().append('<option value="0.0275">公积金基准利率1倍（2.75%）</option><option value="0.03025">公积金基准利率1.1倍</option><option value="0.033">公积金基准利率1.2倍</option>')
  		}else if($(this).val()>5){
  			$("#lending_rate_hpf").empty().append('<option value="0.0325">公积金基准利率1倍（3.25%）</option><option value="0.03575">公积金基准利率1.1倍</option><option value="0.039">公积金基准利率1.2倍</option>')
			$("#lending_rate_commercial").empty().append('<option value="0.049">商业基准利率(4.90%)</option><option value="0.04655">商业基准利率9.5折</option><option value="0.0441">商业基准利率9折</option><option value="0.04312">商业基准利率8.8折</option><option value="0.04263">商业基准利率8.7折</option><option value="0.04214">商业基准利率8.6折</option><option value="0.04165">商业基准利率8.5折</option><option value="0.04018">商业基准利率8.2折</option><option value="0.0392">商业基准利率8折</option><option value="0.0368">商业基准利率7.5折</option><option value="0.0343">商业基准利率7折</option><option value="0.0539">商业基准利率1.1倍</option><option value="0.0588">商业基准利率1.2倍</option><option value="0.0637">商业基准利率1.3倍</option>')
		}
  	
  	
  });
  $('.calculation_button').click(function(){
		window.location.replace("../calculation_results/计算结果.html");
		var price = $('#price_z').val();  //房价总额
		var pric2 = $('#price2_z').val();  //贷款总额
		var proportion  = $('#proportion').val();  //贷款比例
		var year2  = $('#year').val();  //贷款年限
		var price_hpf = $('#hpf_loans').val();//公积金贷款
		var lending_rate_hpf = $('#lending_rate_hpf').val(); //公积金贷款利率
		var price_commercial = $('#commercial_loan').val();//商贷总额
		var lending_rate_commercial = $('#lending_rate_commercial').val(); //商业贷款利率

      if($('#lpr_old').val()==1){
          lending_rate_commercial=lendingRate/100;
      }
		 localStorage.setItem("price", price);
		 localStorage.setItem("pric2", pric2);
		 localStorage.setItem("proportion", proportion);
		 localStorage.setItem("year2", year2);
		 localStorage.setItem("price_hpf",price_hpf);
		 localStorage.setItem("lending_rate_hpf", lending_rate_hpf);
		 localStorage.setItem("price_commercial",price_commercial);
		 localStorage.setItem("lending_rate_commercial", lending_rate_commercial);
		 localStorage.setItem("mortgage_Calculator", 3);

		
	})
    //-----是否是LPR
    if($('#lpr_old').val()==1){
        $('.old_con').hide();
    }else{
        $('.lpr_con').hide();
    }
    $('#lpr_old').change(function(){
        if($(this).val()==1){
            $(this).parents('.loan_details').next('.lpr_con').show();
            $(this).parents('.loan_details').nextAll('.old_con').hide();
        }else{
            $(this).parents('.loan_details').next('.lpr_con').hide();
            $(this).parents('.loan_details').nextAll('.old_con').show();
        }
    });

    var lprNum=4.65;
    var baseNum=0;
    var lendingRate=4.65;
//  	----LPRinput数值变化
    $('#lpr_inp').on("change input",function () {
        lprNum=Number($(this).val());
        lendingRate=Math.floor((lprNum+baseNum/100)*100)/100;
        $('#lpr_rate').html("<span>"+lprNum+"</span> <span>+</span> <span>"+baseNum+"‱</span> <span>=</span> <span style='color:#1a1a1a;'>"+lendingRate+"%</span>");
    });
    //  	----LPR基点input数值变化
    $('#lpr_base').on("change input",function () {
        baseNum=Number($(this).val());
        lendingRate=Math.floor((lprNum+baseNum/100)*100)/100;
        $('#lpr_rate').html("<span>"+lprNum+"</span> <span>+</span> <span>"+baseNum+"‱</span> <span>=</span> <span style='color:#1a1a1a;'>"+lendingRate+"%</span>");
    })
	
});